package com.yonyou.iuap.ansteel.test01.service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yonyou.iuap.context.InvocationInfoProxy;
import com.yonyou.iuap.ansteel.test01.entity.User_suppliers_t1;
import com.yonyou.iuap.ansteel.test01.repository.User_suppliers_t1Mapper;
import com.yonyou.iuap.iweb.exception.WebRuntimeException;

@Service
public class User_suppliers_t1Service {

	@Autowired
	User_suppliers_t1Mapper mapper;

    /**
     * 分页查询方法
     * @param pageRequest
     * @param searchParams
     * @return
     */
    public Page<User_suppliers_t1> selectAllByPage(PageRequest pageRequest, Map<String, Object> searchParams) {
        return mapper.selectAllByPage(pageRequest, searchParams).getPage();
    }

    /**
     * 批量保存，更新，删除方法
     * @param addList
     * @param updateList
     * @param removeList
     */
    @Transactional
    public void save(List<User_suppliers_t1> addList, List<User_suppliers_t1> updateList, List<User_suppliers_t1> removeList) {
        if (CollectionUtils.isNotEmpty(addList)) {
            for (User_suppliers_t1 obj : addList) {
            	obj.setUser_id(UUID.randomUUID().toString());
//            	obj.setDr("0");
//            	obj.setCreateTime(new Date());
//            	obj.setModifyTime(dictType.getCreateTime());
//
//                // 从InvocationInfoProxy获取值
//                obj.setCreator(InvocationInfoProxy.getUsername());
//                obj.setCreatorId(InvocationInfoProxy.getUserid());
            }
            mapper.batchInsert(addList);
        }
        if (CollectionUtils.isNotEmpty(updateList)) {
            for (User_suppliers_t1 dictType : addList) {
//                // 从InvocationInfoProxy获取值
//            	obj.setModifier(InvocationInfoProxy.getUsername());
//            	obj.setModifierId(InvocationInfoProxy.getUserid());
//            	obj.setModifyTime(new Date());
            }
            mapper.batchUpdate(updateList);
        }
        if (CollectionUtils.isNotEmpty(removeList)) {
        	mapper.batchDeleteByPrimaryKey(removeList);
        }
    }

    /**
     * 批量删除
     * @param list
     */
    public void batchDeleteByPrimaryKey(List<User_suppliers_t1> list) {
        if (CollectionUtils.isEmpty(list)) {
            throw new WebRuntimeException("当前没有选中数据!");
        }
        mapper.batchDeleteByPrimaryKey(list);
    }

    /**
     * 用于保存时候的编码重复校验
     * @param dictTypeCode
     * @return
     */
}
